<?php

namespace AppBundle\DataFixtures\ORM;

use AppBundle\Entity\Region;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

/**
 * @see Region
 * @author Vlad Riabchenko <vriabchenko@webnet.fr>
 */
class LoadRegions extends AbstractFixture implements OrderedFixtureInterface
{
    /**
     * @inheritdoc
     */
    public function load(ObjectManager $manager)
    {
        // Regions of France
        $france = $this->getReference('country_france');

        $franceIDF = (new Region())
            ->setName('Île-de-France')
            ->setCountry($france);
        $this->addReference('region_france_idf', $franceIDF);
        $manager->persist($franceIDF);

        $franceHDF = (new Region())
            ->setName('Hauts-de-France')
            ->setCountry($france);
        $this->addReference('region_france_hdf', $franceHDF);
        $manager->persist($franceHDF);

        $franceNormandie = (new Region())
            ->setName('Normandie')
            ->setCountry($france);
        $this->addReference('region_france_normandie', $franceNormandie);
        $manager->persist($franceNormandie);

        // Regions of Germany
        $germany = $this->getReference('country_germany');

        $germanyBaden = (new Region())
            ->setName('Baden-Württemberg')
            ->setCountry($germany);
        $this->addReference('region_germany_baden_wurttemberg', $germanyBaden);
        $manager->persist($germanyBaden);

        $germanyBavaria = (new Region())
            ->setName('Bavaria')
            ->setCountry($germany);
        $this->addReference('region_germany_bavaria', $germanyBavaria);
        $manager->persist($germanyBavaria);

        $manager->flush();
    }

    /**
     * @inheritdoc
     */
    public function getOrder()
    {
        return 2;
    }
}
